package com.apress.messaging.server;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

import cn.hutool.json.JSONObject;

@Service
public class RestTemplateClient {

	@Autowired
	private	RestTemplateBuilder	builder;
	private String rootUri;
	
	public String getRootUri() {
		return rootUri;
	}

	public void setRootUri(String rootUri) {
		this.rootUri = rootUri;
	}

	public	RestTemplate	restTemplate() {
		return	builder.rootUri(rootUri).build();
	}
	
	public	JSONObject	postApi(String	url) {
		JSONObject	result	=	restTemplate().getForObject(url, JSONObject.class);
		return	result;
	}
}
